/*
 *Name: Hengky Kurniawan
 *Class and Section:  CIS D035A Section 61
 *Assignment Number: 3
 *Due Date: May 16
 *Date Submitted: May 9
 * 
 * */

public class SavingsAccount {
	private static float annualInterestRate;	//same interest rate for each object
	private float savingBalance;				//the amount the saver currently has on deposit

	SavingsAccount(){						//default constructor
		annualInterestRate = 0;
		savingBalance = 0;
	}
	
	SavingsAccount(float annInterestRate, float savBalance){	//overloading constructor
		annualInterestRate = annInterestRate;
		savingBalance = savBalance;
	}
	
	protected float getAnnualInterestRate(){
		return annualInterestRate;
	}
	
	protected float getSavingBalance(){
		return savingBalance;
	}

	protected void setAnnualInterestRate(float newAnnualInterestRate){
		annualInterestRate = newAnnualInterestRate;
	}
	
	protected void setSavingBalance(float newBalance){
		savingBalance = newBalance;
	}
	
	protected void calculateMonthlyInterest(){		//calculate the monthly interest by multiplying the balance by annualInterestRate divided by 12; 
													//this interest should be added to savingsBalance. 			
		float monthlyInterest = 0;

		monthlyInterest = annualInterestRate/100/12;
		savingBalance = savingBalance + (savingBalance*monthlyInterest);			//new balance including the interest
	}
	
	protected void deposit(float amountDeposit){			//deposit method in parent class
		savingBalance = savingBalance + amountDeposit;		
	}
	
	protected void withdrawal(float amountWithdraw){
		savingBalance = savingBalance - amountWithdraw;
	}
	
	protected static void  modifyInterestRate(float newint){		//sets the annualInterestRate to a new value.
		annualInterestRate = newint;
	}
	
	
	public static void main(String [] args){			//Main -- Driver program
		SavingsAccount saver1 = new SavingsAccount(4, 2000);		//Set initial balance ($2000) and interest rate (4%) for saver1
		SavingsAccount saver2 = new SavingsAccount(4, 3000);		//Set initial balance ($3000) and interest rate (4%) for saver2
		
		saver1.calculateMonthlyInterest();		//calculate the monthly interest and update the balance for saver 1
		saver2.calculateMonthlyInterest();		//calculate the monthly interest and update the balance for saver 2
		
		System.out.printf("Saver 1 balance after the first month with 4 percent interest per year is " + saver1.savingBalance + "\n");	//print the new balances for each of the savers.
		System.out.printf("Saver 2 balance after the first month with 4 percent interest per year is " + saver2.savingBalance + "\n");	//print the new balances for each of the savers.
		
		modifyInterestRate(5);	//Set the annualInterestRate to 5%
		
		saver1.calculateMonthlyInterest();		//calculate the monthly interest and update the balance for saver 1
		saver2.calculateMonthlyInterest();		//calculate the monthly interest and update the balance for saver 2
		
		System.out.printf("Saver 1 balance after the second month with 5 percent interest per year is " + saver1.savingBalance + "\n");	//print the new balances for each of the savers.
		System.out.printf("Saver 2 balance after the second month with 5 percent interest per year is " + saver2.savingBalance + "\n");	//print the new balances for each of the savers.
	}
}
